package com.seguim.geroglifics;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Geroglific {
	public int width = 0;
	public int height = 0;
	private List rows;
	public Geroglific() {
		rows = new ArrayList();
	}
	public List getRows() {
		return rows;
	}
	public void addRow(Row row) {
		rows.add(row);
	}

	public int getWidth() {
		if (width == 0 || height == 0) {
			computeSize();
		}
		return width;
	}
	public int getHeight() {
		if (width == 0 || height == 0) {
			computeSize();
		}
		return height;
	}
	public void computeSize() {
		int geroglificWidth = 0;
		int geroglificHeight = 0;
		for (Iterator rowIter = rows.iterator(); rowIter.hasNext();) {
			Row row = (Row) rowIter.next();
			int rowWidth = row.getWidth();
			int rowHeight = row.getHeigth();
			if (geroglificWidth < rowWidth) {
				geroglificWidth = rowWidth;
			}
			geroglificHeight += rowHeight;
		}
		width = geroglificWidth;
		height = geroglificHeight;
	}
}
